export const bass = {
    data () {
        return {
            modal1: false,
            czTitle:"添加数据",
            paramsId:'',
            comments:[],
            filter:{
                total:0,
                limit:5,
                page:1,
                title:'',
                name:''
            },
            ids:[],
            model:'users'
        }
    },
    methods: {
        // 增加数据
        ok (paramsId) {
            if(!paramsId){
              this.axios({
                    method:'post',
                    url:`http://localhost:3000/${this.model}/data`,
                    data:this.formRight
                }).then(res=>{
                    this.$Message.info('添加成功');
                    this.getListData()
                })  
            }else{//修改数据
                this.axios({
                    method:'put',
                    url:`http://localhost:3000/${this.model}/data/${paramsId}`,
                    data:this.formRight
                }).then(res=>{
                    this.$Message.info('修改成功');
                    this.getListData()
                })  
            }
        },
        cancel () {
            this.$Message.info('取消操作');
        },
        // 删除数据
        remove (params) {
            this.$Modal.confirm({
                title: '删除',
                content: '<p>你确定删除这条数据</p>',
                onOk: () => {
                    this.axios({
                        method:'delete',
                        url:`http://localhost:3000/${this.model}/data/${params.row._id}`
                    }).then(res=>{
                        this.$Message.info('删除成功');
                        this.getListData()
                    })
                },
                onCancel: () => {
                    this.$Message.info('取消删除');
                }
            });
        },
        onSelectionChange(selection){
            var ids=[];
            for(let i=0;i<selection.length;i++){
                ids.push(selection[i]._id)
            }
            this.ids=ids
        },
        monRemove(){
            this.$Modal.confirm({
                title: '批量删除',
                content: '<p>你确定删除这些数据</p>',
                onOk: () => {
                    this.axios({
                        method:'post',
                        url:`http://localhost:3000/${this.model}/data/removes`,
                        data:{
                            ids:this.ids.toString()
                        }
                    }).then(res=>{
                        this.$Message.info('删除成功');
                        this.getListData()
                    })
                },
                onCancel: () => {
                    this.$Message.info('取消删除');
                }
            });
        },
        // 列表显示
        getListData(){
            this.axios({
                method: 'post',
                url: `http://localhost:3000/${this.model}/list`,
                data: this.filter
            }).then(res=>{
                // console.log(res.data),
                this.filter.total=res.data.total,
                this.comments=res.data.rows;
            })
        },
        onChange(page){
            this.filter.page=page,
            this.getListData()
        },
        ps(pageSize){
            console.log(this.filter.pageSize),
            this.filter.limit=pageSize,
            this.getListData()
        },
        Search(){
            this.getListData()
        }
    },
    mounted(){
        this.getListData()
    }
}